

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="——若发现文章内容有误，敬请指正，望不吝赐教，感谢!@[TOC]  以往记录  Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…   Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境 | 配置Druid+MyBat">
<meta property="og:type" content="article">
<meta property="og:title" content="Web项目实战 _ 购物系统v2.0 _ 开发记录（十）SpringBoot整合阿里云OSS对象存储服务 _ Web将上传的商品图片保存到阿里云，同时将地址保存到数据库">
<meta property="og:url" content="http://example.com/2022/02/22/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E5%8D%81%EF%BC%89SpringBoot%E6%95%B4%E5%90%88%E9%98%BF%E9%87%8C%E4%BA%91OSS%E5%AF%B9%E8%B1%A1%E5%AD%98%E5%82%A8%E6%9C%8D%E5%8A%A1%20_%20Web%E5%B0%86%E4%B8%8A%E4%BC%A0%E7%9A%84%E5%95%86%E5%93%81%E5%9B%BE%E7%89%87%E4%BF%9D%E5%AD%98%E5%88%B0%E9%98%BF%E9%87%8C%E4%BA%91%EF%BC%8C%E5%90%8C%E6%97%B6%E5%B0%86%E5%9C%B0%E5%9D%80%E4%BF%9D%E5%AD%98%E5%88%B0%E6%95%B0%E6%8D%AE%E5%BA%93/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="——若发现文章内容有误，敬请指正，望不吝赐教，感谢!@[TOC]  以往记录  Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…   Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境 | 配置Druid+MyBat">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/00ab081e55b6456da1b257f870949e19.gif#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/a9f570c5d9c34e0ca054a4aaed5f5bb6.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/061d2e2a95964cf7bf19765437eb5d5e.png">
<meta property="article:published_time" content="2022-02-22T14:20:54.000Z">
<meta property="article:modified_time" content="2022-08-22T15:50:56.074Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="JavaWeb">
<meta property="article:tag" content="项目实战:购物系统v2.0">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/00ab081e55b6456da1b257f870949e19.gif#pic_center">
  
  
  
  <title>Web项目实战 _ 购物系统v2.0 _ 开发记录（十）SpringBoot整合阿里云OSS对象存储服务 _ Web将上传的商品图片保存到阿里云，同时将地址保存到数据库 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Web项目实战 _ 购物系统v2.0 _ 开发记录（十）SpringBoot整合阿里云OSS对象存储服务 _ Web将上传的商品图片保存到阿里云，同时将地址保存到数据库"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-02-22 22:20" pubdate>
          2022年2月22日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          6.9k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          58 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Web项目实战 _ 购物系统v2.0 _ 开发记录（十）SpringBoot整合阿里云OSS对象存储服务 _ Web将上传的商品图片保存到阿里云，同时将地址保存到数据库</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <blockquote>
<p>——若发现文章内容有误，敬请指正，望不吝赐教，感谢!<br>@[TOC]</p>
</blockquote>
<h1 id="以往记录"><a href="#以往记录" class="headerlink" title="以往记录"></a>以往记录</h1><hr>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122722369">Web项目实战 | 购物系统v2.0 | 开发记录（一）需求分析 | 技术选型 | 系统设计 | 数据表设计 | SpringBoot、SSM、Thymeleaf、Bootstrap…</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122726356">Web项目实战 | 购物系统v2.0 | 开发记录（二）搭建SpringBoot+SSM框架环境 | 配置Druid+MyBatis | 基于Bootstrap实现登陆页面| 图片验证码接口</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122743352">Web项目实战 | 购物系统v2.0 | 开发记录（三）分页显示 | 根据商品名称进行模糊查询</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122773805">Web项目实战 | 购物系统v2.0 | 开发记录（四）单个页面单个请求解决根据商品类型进行分页查询 | 使用省市区三级联动 | 使用JQuery 插件实现图片上传</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122787974">Web项目实战 | 购物系统v2.0 | 开发记录（五）| 使用base64编码实现头像修改 | 用户个人信息修改 | JQuery动态提示</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122799137">Web项目实战 | 购物系统v2.0 | 开发记录（六）商品详情页面 | 游客访问主页 | 运用Bootstrap4轻量级弹窗实现提示</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://editor.csdn.net/md/?articleId=122849396">Web项目实战 | 购物系统v2.0 | 开发记录（七）SpringBoot整合Shiro框架进行身份认证 | Shiro 加盐(MD5+Salt)验证登陆 | 数据表结构优化避免外键+设置中间表</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122970912">Web项目实战 | 购物系统v2.0 | 开发记录（八）前后端分离初步思路 | JS处理URL参数实用函数 | AJAX 向后台传递Map类型数据 | MyBatis多表查询优化</a></p>
</blockquote>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/122992602">Web项目实战 | 购物系统v2.0 | 开发记录（九）Controller层返回数据的封装 | 商品批量操作 | 五表联立实现商品搜索</a></p>
</blockquote>
<h1 id="运行环境"><a href="#运行环境" class="headerlink" title="运行环境"></a>运行环境</h1><hr>
<ul>
<li>windows10</li>
<li><strong>IDEA 2021.3 专业版</strong></li>
<li><strong>JDK8</strong></li>
<li>SpringBoot2.6.x</li>
<li>JQuery 3.x</li>
<li>Druid 1.2.5</li>
<li>Bootstrap 4.6.0</li>
<li>MySQL 8</li>
<li>Navicat 15</li>
<li><strong>OSS</strong></li>
</ul>
<h1 id="一、OSS概述"><a href="#一、OSS概述" class="headerlink" title="一、OSS概述"></a>一、OSS概述</h1><hr>
<p>官方文档：<a target="_blank" rel="noopener" href="https://help.aliyun.com/document_detail/31817.html">点击查看</a></p>
<p>OSS 全称 <code>Object Storage Service</code>，即对象存储服务，是由阿里云提供的海量、安全、低成本、高可靠的云存储服务。</p>
<p>OSS具有与平台无关的<code>RESTful API</code>接口，可在任意应用、任意地点存储与访问任何类型的数据。网站的图片、视频等文件就可以存放在OSS中（海量数据，交给阿里云平台维护，安全可靠）</p>
<p>更多内容，比如阿里云OSS服务的开通、配置、简单上传等可参考文章<a target="_blank" rel="noopener" href="https://blog.csdn.net/Unirithe/article/details/123056679">【点击查看】</a></p>
<h1 id="二、SpringBoot整合OSS（上传商品图片案例）"><a href="#二、SpringBoot整合OSS（上传商品图片案例）" class="headerlink" title="二、SpringBoot整合OSS（上传商品图片案例）"></a>二、SpringBoot整合OSS（上传商品图片案例）</h1><hr>
<p><strong>注：整合前确保已经开通OSS服务</strong></p>
<p><strong>实现的最终效果：</strong>（前端的图片上传是使用的JQuery插件）<br><img src="https://img-blog.csdnimg.cn/00ab081e55b6456da1b257f870949e19.gif#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="2-1-导入Maven依赖"><a href="#2-1-导入Maven依赖" class="headerlink" title="2.1 导入Maven依赖"></a>2.1 导入Maven依赖</h2><p><code>pom.xml</code></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!-- https://mvnrepository.com/artifact/com.aliyun.oss/aliyun-sdk-oss --&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.aliyun.oss<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>aliyun-sdk-oss<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.13.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><br><br><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>joda-time<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>joda-time<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.9.9<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><br><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.apache.commons<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>commons-lang3<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.8.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>


<h2 id="2-2-通过类配置OSS"><a href="#2-2-通过类配置OSS" class="headerlink" title="2.2 通过类配置OSS"></a>2.2 通过类配置OSS</h2><p>查看OSS相关配置信息可通过以下步骤：</p>
<blockquote>
<p>第一步，进入AccessKey管理<br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/f3879ae432414ce8ab14f048f1aae994.png#">https://img-blog.csdnimg.cn/f3879ae432414ce8ab14f048f1aae994.png#</a> &#x3D;50%x)<br>第二步，查看对应ID的Secret<br><img src="https://img-blog.csdnimg.cn/a9f570c5d9c34e0ca054a4aaed5f5bb6.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>第三步，查看Buncket的访问域名<br><img src="https://img-blog.csdnimg.cn/061d2e2a95964cf7bf19765437eb5d5e.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
</blockquote>
<p>ps：在使用时，也可通过用application声明键值对，由于没有提供起步依赖，所以需手动使用@Value注解注入</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.config;<br><br><span class="hljs-keyword">import</span> com.aliyun.oss.OSS;<br><span class="hljs-keyword">import</span> com.aliyun.oss.OSSClient;<br><span class="hljs-keyword">import</span> com.aliyun.oss.OSSClientBuilder;<br><span class="hljs-keyword">import</span> lombok.Data;<br><span class="hljs-keyword">import</span> org.springframework.context.annotation.Bean;<br><span class="hljs-keyword">import</span> org.springframework.context.annotation.Configuration;<br><br><span class="hljs-meta">@Data</span><br><span class="hljs-meta">@Configuration</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">AliyunConfig</span> &#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-type">String</span> <span class="hljs-variable">endpoint</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;oss-cn-hangzhou.aliyuncs.com&quot;</span>;	<span class="hljs-comment">// OSS服务的地域（这是杭州地区的，根据实际情况修改）</span><br>    <span class="hljs-keyword">private</span> <span class="hljs-type">String</span> <span class="hljs-variable">accessKeyId</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;自己的AccessKey ID&quot;</span>;<br>    <span class="hljs-keyword">private</span> <span class="hljs-type">String</span> <span class="hljs-variable">accessKeySecret</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;自己的AccessKey Secret&quot;</span>;<br>    <span class="hljs-keyword">private</span> <span class="hljs-type">String</span> <span class="hljs-variable">bucketName</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;uni1024&quot;</span>;<br>    <span class="hljs-keyword">private</span> String urlPrefix= <span class="hljs-string">&quot;https://uni1024.oss-cn-hangzhou.aliyuncs.com/&quot;</span>;	<span class="hljs-comment">// 每个用户的OSS域名不同</span><br><br>    <span class="hljs-meta">@Bean</span><br>    <span class="hljs-keyword">public</span> OSS <span class="hljs-title function_">OSSClient</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">OSSClientBuilder</span>().build(endpoint, accessKeyId, accessKeySecret);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="2-3-编写OSS业务层代码"><a href="#2-3-编写OSS业务层代码" class="headerlink" title="2.3 编写OSS业务层代码"></a>2.3 编写OSS业务层代码</h2><p><code>FileUploadResult.java</code> 实体类，用于返回前后端交互的返回值，笔者之前用的是RestResponse类，都差不多，这里主要为了和OSS区分开</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.pojo;<br><br><span class="hljs-keyword">import</span> lombok.Data;<br><br><span class="hljs-comment">// 前后端交互的返回值</span><br><span class="hljs-meta">@Data</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">FileUploadResult</span> &#123;<br>    <span class="hljs-comment">// 文件唯一标识</span><br>    <span class="hljs-keyword">private</span> String uid;<br>    <span class="hljs-comment">// 文件名</span><br>    <span class="hljs-keyword">private</span> String name;<br>    <span class="hljs-comment">// 状态有：uploading done error removed</span><br>    <span class="hljs-keyword">private</span> String status;<br>    <span class="hljs-comment">// 服务端响应内容，如：&#x27;&#123;&quot;status&quot;: &quot;success&quot;&#125;&#x27;</span><br>    <span class="hljs-keyword">private</span> String response;<br>&#125;<br><br></code></pre></td></tr></table></figure>
<p><code>FileUploadService.java</code> 实现文件上传的业务逻辑层</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.service;<br><br><span class="hljs-keyword">import</span> com.aliyun.oss.OSS;<br><br><span class="hljs-keyword">import</span> com.uni.config.AliyunConfig;<br><span class="hljs-keyword">import</span> com.uni.pojo.FileUploadResult;<br><span class="hljs-keyword">import</span> org.joda.time.DateTime;<br><span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;<br><span class="hljs-keyword">import</span> org.springframework.stereotype.Service;<br><span class="hljs-keyword">import</span> org.springframework.util.Base64Utils;<br><br><span class="hljs-keyword">import</span> java.io.ByteArrayInputStream;<br><span class="hljs-keyword">import</span> java.util.regex.Matcher;<br><span class="hljs-keyword">import</span> java.util.regex.Pattern;<br><br><span class="hljs-meta">@Service</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">FileUploadService</span> &#123;<br>    <span class="hljs-comment">// 允许上传的格式</span><br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String[] IMAGE_TYPE = <span class="hljs-keyword">new</span> <span class="hljs-title class_">String</span>[]&#123;<span class="hljs-string">&quot;bmp&quot;</span>, <span class="hljs-string">&quot;jpg&quot;</span>,<br>            <span class="hljs-string">&quot;jpeg&quot;</span>, <span class="hljs-string">&quot;gif&quot;</span>, <span class="hljs-string">&quot;png&quot;</span>&#125;;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-type">String</span> <span class="hljs-variable">ERROR</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;error&quot;</span>;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-type">String</span> <span class="hljs-variable">DONE</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;done&quot;</span>;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-type">String</span> <span class="hljs-variable">SUCCESS</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;success&quot;</span>;<br>    <span class="hljs-meta">@Autowired</span><br>    <span class="hljs-keyword">private</span> OSS ossClient;<br>    <span class="hljs-meta">@Autowired</span><br>    <span class="hljs-keyword">private</span> AliyunConfig aliyunConfig;<br><br>    <span class="hljs-keyword">public</span> FileUploadResult <span class="hljs-title function_">upload</span><span class="hljs-params">(String uploadFile, Long prodId)</span> &#123;<br><br>        <span class="hljs-type">Pattern</span> <span class="hljs-variable">pattern</span> <span class="hljs-operator">=</span> Pattern.compile(<span class="hljs-string">&quot;image/(.*);&quot;</span>);<br>        <span class="hljs-type">Matcher</span> <span class="hljs-variable">matcher</span> <span class="hljs-operator">=</span> pattern.matcher(uploadFile);<br>        <span class="hljs-type">String</span> <span class="hljs-variable">uploadType</span> <span class="hljs-operator">=</span> matcher.find() ? matcher.group(<span class="hljs-number">1</span>) : <span class="hljs-literal">null</span>;<br>        <span class="hljs-comment">// 校验图片格式</span><br>        <span class="hljs-type">boolean</span> <span class="hljs-variable">isLegal</span> <span class="hljs-operator">=</span> <span class="hljs-literal">false</span>;<br>        <span class="hljs-keyword">for</span> (String type : IMAGE_TYPE) &#123;<br><br>            <span class="hljs-keyword">if</span> (type.equals(uploadType)) &#123;<br>                isLegal = <span class="hljs-literal">true</span>;<br>                <span class="hljs-keyword">break</span>;<br>            &#125;<br>        &#125;<br>        <span class="hljs-comment">//封装Result对象，并且将文件的byte数组放置到result对象中</span><br>        <span class="hljs-type">FileUploadResult</span> <span class="hljs-variable">fileUploadResult</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">FileUploadResult</span>();<br>        <span class="hljs-keyword">if</span> (!isLegal) &#123;<br>            fileUploadResult.setStatus(ERROR);<br>            <span class="hljs-keyword">return</span> fileUploadResult;<br>        &#125;<br>        <span class="hljs-comment">//文件新路径</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">filePath</span> <span class="hljs-operator">=</span> getFilePath(prodId, uploadType);<br>        <span class="hljs-comment">// 上传到阿里云</span><br>        <span class="hljs-keyword">try</span> &#123;<br>            <span class="hljs-comment">// 上传时需去掉base64编码的data:image/xxx;base64前缀</span><br>            ossClient.putObject(aliyunConfig.getBucketName(), filePath, <span class="hljs-keyword">new</span><br>                    <span class="hljs-title class_">ByteArrayInputStream</span>(Base64Utils.decodeFromString(uploadFile.split(<span class="hljs-string">&quot;,&quot;</span>)[<span class="hljs-number">1</span>].trim())));<br>        &#125; <span class="hljs-keyword">catch</span> (Exception e) &#123;<br>            e.printStackTrace();<br>            <span class="hljs-comment">//上传失败</span><br>            fileUploadResult.setStatus(ERROR);<br>            <span class="hljs-keyword">return</span> fileUploadResult;<br>        &#125;<br>        fileUploadResult.setStatus(DONE);<br>        fileUploadResult.setResponse(SUCCESS);<br>        <span class="hljs-type">String</span> <span class="hljs-variable">fileUrl</span> <span class="hljs-operator">=</span> <span class="hljs-built_in">this</span>.aliyunConfig.getUrlPrefix() + filePath;<br>        fileUploadResult.setName(fileUrl);<br>        fileUploadResult.setUid(String.valueOf(System.currentTimeMillis()));<br>        <span class="hljs-keyword">return</span> fileUploadResult;<br>    &#125;<br><br>    <span class="hljs-keyword">private</span> String <span class="hljs-title function_">getFilePath</span><span class="hljs-params">(Long prodId, String fileType)</span> &#123;<br>        <span class="hljs-type">DateTime</span> <span class="hljs-variable">dateTime</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">DateTime</span>();<br>        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;images/product/&quot;</span> + prodId + <span class="hljs-string">&quot;/&quot;</span> + dateTime.toString(<span class="hljs-string">&quot;yyyy-MM-dd&quot;</span>)<br>                + System.currentTimeMillis() + <span class="hljs-string">&quot;.&quot;</span> +<br>                fileType;<br>    &#125;<br><br>&#125;<br></code></pre></td></tr></table></figure>
<h2 id="2-4-编写控制层代码"><a href="#2-4-编写控制层代码" class="headerlink" title="2.4 编写控制层代码"></a>2.4 编写控制层代码</h2><p>控制层主要作用就是调用业务层的逻辑代码，调用完毕后将结果反馈给View视图。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@PostMapping(&quot;/update/&#123;prodId&#125;&quot;)</span><br><span class="hljs-keyword">public</span> String <span class="hljs-title function_">updateProdcutInfo</span><span class="hljs-params">(<span class="hljs-meta">@PathVariable</span> Long prodId, Product prod)</span>&#123;<br>    <span class="hljs-comment">// 图片单独处理</span><br>    <span class="hljs-type">Product</span> <span class="hljs-variable">oldProduct</span> <span class="hljs-operator">=</span> productService.getProductWithProviderById(prodId);<br>    prod.setImg(oldProduct.getImg());<br>    <span class="hljs-comment">// 执行修改业务</span><br>    <span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> productService.modifyProductById(prod);<br>    <span class="hljs-keyword">return</span> i == <span class="hljs-number">2</span> ? RestResponse.ok(<span class="hljs-string">&quot;修改商品信息成功!&quot;</span>).toJSONString()<br>            : RestResponse.fail(<span class="hljs-string">&quot;修改商品信息失败&quot;</span>).toJSONString();<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="2-5-编写前端JQuery-AJAX请求代码"><a href="#2-5-编写前端JQuery-AJAX请求代码" class="headerlink" title="2.5 编写前端JQuery AJAX请求代码"></a>2.5 编写前端JQuery AJAX请求代码</h2><p>笔者偷了个懒，这里直接将AJAX的代码嵌入到了插件的函数里，主要部分就在$.ajax</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-comment">//裁剪后的处理: 修改商品图片</span><br>$(<span class="hljs-string">&quot;#sureCut&quot;</span>).<span class="hljs-title function_">on</span>(<span class="hljs-string">&quot;click&quot;</span>,<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-keyword">if</span> ($(<span class="hljs-string">&quot;#tailoringImg&quot;</span>).<span class="hljs-title function_">attr</span>(<span class="hljs-string">&quot;src&quot;</span>) == <span class="hljs-literal">null</span> )&#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br>    &#125;<span class="hljs-keyword">else</span>&#123;<br>        <span class="hljs-keyword">let</span> cas = $(<span class="hljs-string">&#x27;#tailoringImg&#x27;</span>).<span class="hljs-title function_">cropper</span>(<span class="hljs-string">&#x27;getCroppedCanvas&#x27;</span>);<span class="hljs-comment">//获取被裁剪后的canvas</span><br>        <span class="hljs-keyword">let</span> base64url = cas.<span class="hljs-title function_">toDataURL</span>(<span class="hljs-string">&#x27;image/png&#x27;</span>); <span class="hljs-comment">//转换为base64地址形式</span><br>        $(<span class="hljs-string">&quot;#finalImg&quot;</span>).<span class="hljs-title function_">prop</span>(<span class="hljs-string">&quot;src&quot;</span>,base64url);<span class="hljs-comment">//显示为图片的形式</span><br>        $.<span class="hljs-title function_">ajax</span>(&#123;<br>            <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;/admin/product/update/&#x27;</span> + $(<span class="hljs-string">&#x27;#form-id&#x27;</span>).<span class="hljs-title function_">val</span>(),<br>            <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;PUT&#x27;</span>,<br>            <span class="hljs-attr">data</span>: &#123;<span class="hljs-attr">base64url</span>:base64url&#125;,<br>            <span class="hljs-attr">dataType</span>: <span class="hljs-string">&#x27;JSON&#x27;</span>,<br>            <span class="hljs-attr">error</span>: <span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span>&#123; <span class="hljs-title function_">alert</span>(<span class="hljs-string">&#x27;修改头像请求失败.&#x27;</span>); <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(err.<span class="hljs-property">responseText</span>);&#125;,<br>            <span class="hljs-attr">success</span>: <span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span> &#123;<br>                <span class="hljs-title function_">open_toast</span>(data[<span class="hljs-string">&#x27;code&#x27;</span>] === <span class="hljs-number">1</span> ? <span class="hljs-string">&#x27;success&#x27;</span> : <span class="hljs-string">&#x27;fail&#x27;</span>, data[<span class="hljs-string">&#x27;message&#x27;</span>])&#125;<br>        &#125;)<br><br>        <span class="hljs-comment">//关闭裁剪框</span><br>        <span class="hljs-title function_">closeTailor</span>();<br>    &#125;<br>&#125;);<br></code></pre></td></tr></table></figure>

<p>至此，SpringBoot整合OSS的简单应用就结束了。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2-0/" class="category-chain-item">项目实战:购物系统v2.0</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/JavaWeb/">#JavaWeb</a>
      
        <a href="/tags/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv2-0/">#项目实战:购物系统v2.0</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Web项目实战 _ 购物系统v2.0 _ 开发记录（十）SpringBoot整合阿里云OSS对象存储服务 _ Web将上传的商品图片保存到阿里云，同时将地址保存到数据库</div>
      <div>http://example.com/2022/02/22/Web项目实战 _ 购物系统v2.0 _ 开发记录（十）SpringBoot整合阿里云OSS对象存储服务 _ Web将上传的商品图片保存到阿里云，同时将地址保存到数据库/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年2月22日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/02/23/BUG%E5%B7%B2%E8%A7%A3%E5%86%B3%20_%20%E4%BD%BF%E7%94%A8JQuery%E7%9A%84serialize%E5%BA%8F%E5%88%97%E5%8C%96%E8%A1%A8%E5%8D%95%E6%97%B6%EF%BC%8C%E6%97%A0%E6%B3%95%E8%8E%B7%E5%8F%96%E5%88%B0%E8%A1%A8%E5%8D%95%E5%86%85%E6%9C%AA%E9%80%89%E4%B8%AD%E5%8D%95_%E5%A4%9A%E9%80%89%E6%A1%86%E7%9A%84%E5%86%85%E5%AE%B9%20_%20%E6%89%8B%E5%8A%A8%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AA%E5%8A%A0%E5%BC%BA%E7%89%88%E7%9A%84serialize%E6%96%B9%E6%B3%95%E8%8E%B7%E5%8F%96/" title="BUG已解决 _ 使用JQuery的serialize序列化表单时，无法获取到表单内未选中单_多选框的内容 _ 手动编写一个加强版的serialize方法获取">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">BUG已解决 _ 使用JQuery的serialize序列化表单时，无法获取到表单内未选中单_多选框的内容 _ 手动编写一个加强版的serialize方法获取</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/02/21/%E9%98%BF%E9%87%8C%E4%BA%91OSS%20_%20%E5%AF%B9%E8%B1%A1%E5%AD%98%E5%82%A8%E6%9C%8D%E5%8A%A1%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8%20_%20%E5%8F%82%E8%80%83%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3%E5%AE%9E%E7%8E%B0%E4%BD%BF%E7%94%A8JavaSDK%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6%20_%20%E6%9C%AC%E5%9C%B0%E4%B8%8A%E4%BC%A0%E4%B8%8Eweb%E4%B8%8A%E4%BC%A0%E6%A1%88%E4%BE%8B/" title="阿里云OSS_对象存储服务快速入门_参考官方文档实现使用JavaSDK上传文件_本地上传与web上传案例">
                        <span class="hidden-mobile">阿里云OSS_对象存储服务快速入门_参考官方文档实现使用JavaSDK上传文件_本地上传与web上传案例</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
